# conding = utf-8
import time

import yaml
from selenium.webdriver import ActionChains, Keys

from pages.page import Page
from pages.lyz.finance.revenue import left_menu_sys, left_menu, btn_unfold, id_send, time_began, time_left, \
    time_began_open, time_finishes_open, find_btn, find_reset, find_expected, unit, unit_open, operator, operator_open, \
    finance, finance_open, account, account_open, state, state_open, remark, \
    add_btn, add_operator, add_finance, project, project_open, amount, cancel, \
    add_remark, insert, label, remove, remove_identify, stored, get_tishi, view, \
    view_btn, update, handler_add, handler_btn, handler_name, handler_type, handler_sort, handler_yes, handle_expected, \
    handler_no, rent, get_update, delete, delete_btn, delete_expected, batch, batch_btn, pl_delete, pl_audit, pl_anti_audit, queding


class RevenuePages(Page):
    def open_sales_order(self):
        '''
        打开管理员UI，如果已经打开则不会执行单击动作
        :return:
        '''
        if self.display(left_menu) is False:  # 如果是隐藏状态则单击
            self.click(left_menu_sys)
        self.click(left_menu)

    def btn_unfold(self):
        self.click(btn_unfold)

    def id_send(self, value):
        self.send_keys(id_send, value)

    def time_began(self):
        self.click(time_began)
        time.sleep(1)
        self.click(time_left)
        time.sleep(1)
        self.click(time_left)
        time.sleep(1)
        self.click(time_began_open)
        time.sleep(1)
        self.click(time_finishes_open)

    def search_result_text(self, value):
        if value == 'SR00000000680':
            return self.text(find_expected)

    def unit(self):
        self.click(unit)

    def unit_open(self):
        self.click(unit_open)

    def operator(self):
        self.click(operator)

    def operator_open(self):
        self.click(operator_open)

    def finance(self):
        self.click(finance)

    def finance_open(self):
        self.click(finance_open)

    def account(self):
        self.click(account)

    def account_open(self):
        self.click(account_open)

    def state(self):
        self.click(state)

    def state_open(self):
        self.click(state_open)

    def find_btn(self):
        self.click(find_btn)

    def find_reset(self):
        self.click(find_reset)

    def remark(self, value):
        self.send_keys(remark, value)

    def add_btn(self):
        self.click(add_btn)

    def add_operator(self):
        self.click(add_operator)  # 点击下拉框
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def add_finance(self):
        self.click(add_finance)  # 点击下拉框
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def project(self):
        self.click(project)

    def project_open(self):
        self.click(project_open)

    def amount(self, value):
        self.send_keys(amount, value)

    def add_remark(self, value):
        self.send_keys(add_remark, value)

    def insert(self):
        self.click(insert)

    def label(self):
        self.click(label)

    def remove(self):
        self.click(remove)

    def remove_identify(self):
        self.click(remove_identify)

    def cancel(self):
        self.click(cancel)

    def stored(self):
        self.click(stored)

    def amount_exists(self):
        return self.is_exists(get_tishi)

    def view(self):
        self.click(view)

    def view_btn(self):
        self.click(view_btn)

    def get_update(self):
        return self.is_exists(get_update)

    def update_method(self):
        if self.is_exists(get_update):  # 调用 is_exists 方法，传入 get_tishi 定位器
            return True
        else:
            return False

    def some_method(self):
        # 判断元素是否存在并返回 True 或 False
        if self.is_exists(get_tishi):  # 调用 is_exists 方法，传入 get_tishi 定位器
            return True
        else:
            return False

    def update(self):
        self.click(update)

    def handler_btn(self):
        self.click(handler_btn)

    def handler_add(self):
        self.click(handler_add)

    def handler_name(self, value):
        self.send_keys(handler_name, value)

    def handler_type(self):
        self.click(handler_type)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def handler_sort(self, value):
        self.send_keys(handler_sort, value)

    def handler_yes(self):
        self.click(handler_yes)

    def handler_no(self):
        self.click(handler_no)

    def handler_tishi(self):
        return self.is_exists(handle_expected)

    def handle_expected(self):
        if self.is_exists(handle_expected):  # 调用 is_exists 方法，传入 get_tishi 定位器
            return True
        else:
            return False

    def open_one(self):
        self.click(add_operator)
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def open_tow(self):
        self.click(add_finance)  # 点击下拉框
        actions = ActionChains(self.driver)  # 定义动作链
        actions.send_keys(Keys.UP)  # 下键 # 下键
        actions.send_keys(Keys.ENTER)  # 回车键
        actions.perform()

    def rent(self):
        self.click(rent)

    def delete(self):
        self.click(delete)

    def delete_btn(self):
        self.click(delete_btn)

    def delete_expected(self):
        return self.text(delete_expected)

    def batch(self):
        self.click(batch)

    def batch_btn(self):
        self.click(batch_btn)

    def pl_audit(self):
        self.click(pl_audit)

    def pl_delete(self):
        self.click(pl_delete)

    def pl_anti_audit(self):
        self.click(pl_anti_audit)

    def queding(self):
        self.click(queding)
